package com.qiaofang.applet.service.member.service.mapstruct;

import com.qiaofang.applet.service.member.domain.Appointment;
import com.qiaofang.applet.service.member.domain.Employee;
import com.qiaofang.applet.service.member.service.dto.AppointmentEmpListDto;
import com.qiaofang.applet.service.member.service.dto.AppointmentResponseDto;
import com.qiaofang.applet.service.member.service.dto.AppointmentSubmitDto;
import com.qiaofang.applet.service.member.service.dto.MyAppointmentListDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface AppointmentMapper {
    AppointmentEmpListDto empDomainToAppointmentDto(Employee employee);

    Appointment submitDtoToDomain(AppointmentSubmitDto submitDto);

    default List<MyAppointmentListDto> domainToMyListDto(List<Appointment> appointmentList) {
        if ( appointmentList == null ) {
            return null;
        }

        List<MyAppointmentListDto> list = new ArrayList<MyAppointmentListDto>( appointmentList.size() );
        for ( Appointment appointment : appointmentList ) {
            list.add( appointmentToMyAppointmentListDto( appointment ) );
        }

        return list;
    }

    default MyAppointmentListDto appointmentToMyAppointmentListDto(Appointment appointment) {
        if ( appointment == null ) {
            return null;
        }

        MyAppointmentListDto myAppointmentListDto = new MyAppointmentListDto();

        myAppointmentListDto.setId( appointment.getId() );
        myAppointmentListDto.setMemberId( appointment.getMemberId() );
        myAppointmentListDto.setMemberPhone( appointment.getMemberPhone() );
        myAppointmentListDto.setEmployeeUniqueUuid( appointment.getEmployeeUniqueUuid() );
        myAppointmentListDto.setEmployeeName( appointment.getEmployeeName() );
        myAppointmentListDto.setBusinessType( appointment.getBusinessType() );
        myAppointmentListDto.setBusinessUuid( appointment.getBusinessUuid() );
        myAppointmentListDto.setBusinessName( appointment.getBusinessName() );
        myAppointmentListDto.setCityName( appointment.getCityName() );
        myAppointmentListDto.setDistrictName( appointment.getDistrictName() );
        myAppointmentListDto.setAppointmentName( appointment.getAppointmentName() );
        myAppointmentListDto.setVisitorNum( appointment.getVisitorNum() );
        myAppointmentListDto.setAppointmentPhone( appointment.getAppointmentPhone() );
        myAppointmentListDto.setAppointmentTime( appointment.getAppointmentTime() );
        if ( appointment.getCreateTime() != null ) {
            myAppointmentListDto.setCreateTime( new SimpleDateFormat("yyyy-MM-dd HH:mm").format( appointment.getCreateTime() ) );
        }
        myAppointmentListDto.setVisitTime( appointment.getVisitTime() );
        myAppointmentListDto.setCityCode( appointment.getCityCode() );

        return myAppointmentListDto;
    }




    default List<AppointmentResponseDto> domainToAppointmentResponseDto(List<Appointment> appointments){
        if ( appointments == null ) {
            return null;
        }

        List<AppointmentResponseDto> list = new ArrayList<AppointmentResponseDto>( appointments.size() );
        for ( Appointment appointment : appointments ) {
            list.add( appointmentToAppointmentResponseDto( appointment ) );
        }

        return list;
    }

    default AppointmentResponseDto appointmentToAppointmentResponseDto(Appointment appointment) {
        if ( appointment == null ) {
            return null;
        }

        AppointmentResponseDto appointmentResponseDto = new AppointmentResponseDto();

        appointmentResponseDto.setId( appointment.getId() );
        appointmentResponseDto.setMemberId( appointment.getMemberId() );
        appointmentResponseDto.setMemberPhone( appointment.getMemberPhone() );
        appointmentResponseDto.setDistrictName( appointment.getDistrictName() );
        appointmentResponseDto.setAppointmentName( appointment.getAppointmentName() );
        appointmentResponseDto.setVisitorNum( appointment.getVisitorNum() );
        appointmentResponseDto.setBusinessName( appointment.getBusinessName() );
        appointmentResponseDto.setBusinessUuid( appointment.getBusinessUuid());
        appointmentResponseDto.setBusinessType( appointment.getBusinessType() );
        appointmentResponseDto.setAppointmentPhone( appointment.getAppointmentPhone() );
        appointmentResponseDto.setCreateTime( new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(appointment.getCreateTime()) );
        appointmentResponseDto.setAppointmentTime( appointment.getAppointmentTime() );
        appointmentResponseDto.setEmployeeName( appointment.getEmployeeName() );
        appointmentResponseDto.setEmployeeUniqueUuid( appointment.getEmployeeUniqueUuid() );
        appointmentResponseDto.setStatus( appointment.getStatus() );
        appointmentResponseDto.setVisitTime( appointment.getVisitTime() );

        return appointmentResponseDto;
    }
}
